package com.xzlf.controller;

import com.xzlf.config.RSAProperties;
import com.xzlf.entity.User;
import com.xzlf.util.RSAUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@Controller
@Slf4j
public class LoginController {
    @Autowired
    private RSAProperties rsaProperties;

    @GetMapping("/{page}")
    public String login(@PathVariable String page){
        return page;
    }

    @ResponseBody
    @PostMapping("/loginRequest")
    public Object loginRequest(@RequestBody User user){
        log.info("user{}", user);
        String password = user.getPassword();
        String s = RSAUtil.decryptDataOnJava(password, rsaProperties.getPrivateKey());
        log.info("解密后密码：{}", s);
        user.setPassword(s);
        String addr = RSAUtil.encryptedDataOnJava("广东深圳", rsaProperties.getPublicKey());
        user.setAddr(addr);
        log.info("user{}", user);
        return user;
    }
}
